package jtk.project4.fleet.screen.browsePurchaseOrder;

import java.awt.FlowLayout;

import javax.swing.SortOrder;

import jtk.project4.fleet.action.CancelAction;
import jtk.project4.fleet.action.SubmitAction;
import jtk.project4.fleet.domain.Po;
import jtk.project4.fleet.event.EquipmentEvent;
import jtk.project4.fleet.field.ButtonBrowsePurchaseOrdersFields;
import jtk.project4.fleet.field.BrowsePurchaseOrdersField;
import jtk.project4.fleet.field.DataIntervalSettingsField;
import jtk.project4.fleet.field.IdentificationField;
import jtk.project4.fleet.field.ViewOptionsField;
import nl.coderight.jazz.action.Action;
import nl.coderight.jazz.form.FormHeader;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.field.TableField;
import nl.coderight.jazz.form.field.TableField.AutoResizeMode;
import nl.coderight.jazz.form.field.button.PushButton;

public class BrowsePurchaseOrdersView extends FormView {
	//private FormHeader formHeader;
	private PushButton helpButton;
	private PushButton closeButton;
	private TableField<Po> browsePurcaseOrdersTable ;
	//private Action helpAction;
	//private Action closeAction;
		
	@Override
	protected void init() {
		//createAction();
		createFields();
		createLayout();		
	}	
	
	private void createFields(){
		helpButton = new PushButton("button.help");
		closeButton = new PushButton("button.close");
		bikinTable();
	}
	
	private void createLayout() {
		addField(createForm());
	}
	
	private GroupControl createForm() {
		GroupControl form = new GroupControl();
		form.addField(createGroupField(),NORTH);
		form.addField(new ViewOptionsField("View Option"), WEST);
		form.addField(new DataIntervalSettingsField("Data Interval Settings"), EAST);
		
		form.addField(createButtons(), SOUTH);		
		return form;
	}
	
	private GroupControl createGroupField(){
		GroupControl form = new GroupControl();
		form.addField(browsePurcaseOrdersTable, NORTH);
		form.addField(new ButtonBrowsePurchaseOrdersFields("browse"),SOUTH);
		return form;
		
	}
	
	private GroupControl createButtons() {
		GroupControl buttons = new GroupControl();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(helpButton);
		buttons.addField(closeButton);
		return buttons;
	}
	
	private void bikinTable(){
		browsePurcaseOrdersTable = new TableField<Po>("pos","po");
		browsePurcaseOrdersTable.setTitle("BrowsePurcaseOrdersTable.header.table");
		browsePurcaseOrdersTable.setAutoResizeMode(AutoResizeMode.OFF);
		browsePurcaseOrdersTable.getSelectionValues();
		
		//add columns
		browsePurcaseOrdersTable.addColumn("label.po","poId");
		//browsePurcaseOrdersTable.addColumn("label.poDate","poDate");
		//browsePurcaseOrdersTable.addColumn("label.dateExpected","dateE");
		//browsePurcaseOrdersTable.addColumn("label.status","status");
		//browsePurcaseOrdersTable.addColumn("label.dateClosed","dateClosed");
		//browsePurcaseOrdersTable.addColumn("label.location","location");
		browsePurcaseOrdersTable.addColumn("label.vendor","vendor");
		//browsePurcaseOrdersTable.addColumn("label.buyerName","buyerName");
		//browsePurcaseOrdersTable.addColumn("label.shipVia","shipVia");
		//browsePurcaseOrdersTable.addColumn("label.invoice","invoice");
		//browsePurcaseOrdersTable.addColumn("label.order","order");
		
		//Sort
		browsePurcaseOrdersTable.sort("poId", SortOrder.ASCENDING);
	}
	
}
